<?php


namespace App\Admin\Controllers\Wechat;


use App\Models\wechat\CmcTemplateMessage;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Form;
use Dcat\Admin\Http\Controllers\AdminController;

class WechatTemplate extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {

        return Grid::make(new CmcTemplateMessage(), function (Grid $grid) {
            $grid->column('id','编号')->width('50px')->sortable();
            $grid->column('tempkey','模板编号');
            $grid->column('tempid','模板ID')->width('400px');
            $grid->column('name','模板名称')->width('130px');
            $grid->column('content','回复内容');
            $grid->column('status', '状态')->switch()->filter(
                Grid\Column\Filter\In::make([
                    0 => '启用',
                    1 => '不启用',
                ])
            );
            $grid->column('created_at','添加时间')->width('120px')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CmcTemplateMessage(), function (Show $show) {
            $status = ['1'=>'启用','0'=>'禁用'];
            $type = ['1'=>'微信模板消息' ,'2'=>'订阅消息'];
            $show->field('id','编号');
            $show->field('type','消息类型')->using($type);
            $show->field('tempkey','模板编号');
            $show->field('tempid','模板ID');
            $show->field('name','模板名称');
            $show->field('content','回复内容');
            $show->field('status', '状态')->using($status);
            $show->field('created_at','添加时间');

        });
    }



    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CmcTemplateMessage(), function (Form $form) {
            $form->select('type', '消息类型')->options([0 => '订阅消息', 1 => '微信模板消息']);
            $form->text('tempkey','模板编号');
            $form->text('tempid','模板ID');
            $form->text('name','模板名称');
            $form->textarea('content','模板内容')->rows(10);
            $form->radio('status', '状态')->options(['1' => '启用', '0'=> '不启用'])->default('1');
        });
    }

}